package com.sdkteam.Others;

import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.CountDownTimer;
import android.widget.TextView;

import com.sdkteam.Ailatrieuphu.Main;
import com.sdkteam.Ailatrieuphu.R;

public class MilTimer extends CountDownTimer {
	long stop = 60;
	TextView tvTime;
	Main activity;
	public MediaPlayer mp;
	public boolean checkend = true;
	public MilTimer(long millisInFuture, long countDownInterval,
			TextView tvTime, Main activity) {
		super(millisInFuture, countDownInterval);
		this.tvTime = tvTime;
		this.activity = activity;
//		this.stop = stop;
	}


	@Override
	public void onFinish() {
		checkend = false;
		tvTime.setText("00:00");
		activity.disableButton();
		if (ControlStatic.Sound) {
			mp = MediaPlayer.create(activity.getApplicationContext(),
					R.raw.out_of_time);
			mp.start();
			mp.setOnCompletionListener(new OnCompletionListener() {

				public void onCompletion(MediaPlayer mp) {
					activity.saveScore(activity.level -1, false);
				}
			});
		} else {
			activity.saveScore(activity.level -1, false);
		}

	}

	@Override
	public void onTick(long millisUntilFinished) {
		stop = millisUntilFinished / 1000;
		tvTime.setText("0"+":"+stop);

	}
	
	public long getStop(){
		return stop;
	}
	public boolean getCheckend(){
		return checkend;
	}

}
